﻿using DevExpress.XtraGrid.Demos.util;
using DXApplicationTangche.Const;
using DXApplicationTangche.UC.成品出库单.service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.成品出库单
{
    public partial class FormLuna销售出库单 : DevExpress.XtraEditors.XtraForm
    {
        private List<StockInOutDetailDTO> StockInOutDetailDTOs = new List<StockInOutDetailDTO>();
        private StockInOutDetailDTO stockInOutDetailDTO = new StockInOutDetailDTO();
        private String sessionId;
        public FormLuna销售出库单()
        {
            InitializeComponent();
            this.sessionId = new FunctionHelper().Uuid;
        }

        private void textBox扫描_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13)
            {
                if (!String.IsNullOrWhiteSpace(this.textBox扫描.Text))
                {
                    try
                    {
                        //扫描成衣码出库
                        this.stockInOutDetailDTO =
                            成品出库单Service.preStockInOutDetailWithCustomerInfoByBarcode(
                                this.sessionId,
                                this.textBox扫描.Text.Trim(),
                                0,
                                "工厂销售出库",
                                "5");
                        try { this.stockInOutDetailDTO.styleSizeCd = this.stockInOutDetailDTO.styleSizeCd.Replace("IGS_GROUP_SIZE-", "").Replace("EGS_GROUP_SIZE-", ""); } catch { }
                        if (!String.IsNullOrEmpty(this.stockInOutDetailDTO.barcode))
                        {
                            if (this.StockInOutDetailDTOs.Count > 0)
                            {
                                if (!this.StockInOutDetailDTOs.Exists(dto => dto.barcode.Equals(this.stockInOutDetailDTO.barcode)))
                                {
                                    this.StockInOutDetailDTOs.Add(this.stockInOutDetailDTO);
                                }
                            }
                            else
                            {
                                this.StockInOutDetailDTOs.Add(this.stockInOutDetailDTO);
                            }
                        }
                        this.gridControl成品出库.DataSource = this.StockInOutDetailDTOs;
                        this.gridView成品出库.RefreshData();
                        this.gridView成品出库.BestFitColumns();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    this.textBox扫描.Clear();
                }
                else
                {
                    MessageBox.Show("请扫码");
                }
            }
        }

        private void simpleButton确认_Click(object sender, EventArgs e)
        {
            if (this.StockInOutDetailDTOs.Count > 0)
            {
                String str = FunctionHelper.JsonSerialization(this.StockInOutDetailDTOs);
                new Form成品出库单确认(this.sessionId, "5", "顺秋服装厂", StockInOutTypeConst.FactorySaleOut,
                    "上海Luna店铺定制销售出库",this.StockInOutDetailDTOs).ShowDialog();
                this.StockInOutDetailDTOs.Clear();
                this.sessionId = new FunctionHelper().Uuid;
                this.gridControl成品出库.DataSource = this.StockInOutDetailDTOs;
                this.gridView成品出库.RefreshData();
                this.gridView成品出库.BestFitColumns();
            }
            else
            {
                MessageBox.Show("无确认数据");
            }
        }

        private void simpleButton取消_Click(object sender, EventArgs e)
        {
            this.sessionId = new FunctionHelper().Uuid;
            this.StockInOutDetailDTOs.Clear();
            this.stockInOutDetailDTO = new StockInOutDetailDTO();
            this.gridControl成品出库.DataSource = this.StockInOutDetailDTOs;
            this.gridView成品出库.RefreshData();
            this.gridView成品出库.BestFitColumns();
        }
    }
}
